import base64
import urllib
import subprocess
import os
import json

def decode(data):
    return base64.b64decode(urllib.unquote(data))

def showline(line):
    js = json.loads(line)
   # print js['mag']['data']
    if(js['mag']['type']=='network_read'):
        print '.'*62
        print '.'*25,'network_read','.'*25
        print '.'*23,js['mag']['rip'],':',js['mag']['rport'],'.'*25
        print '.'*62
        print decode(js['mag']['data'])
    elif(js['mag']['type']=='network_send'):
        print '.'*62
        print '.'*25,'network_send','.'*25
        print '.'*23,js['mag']['rip'],':',js['mag']['rport'],'.'*25
        print '.'*62
        print decode(js['mag']['data'])
    


p = subprocess.Popen('adb logcat', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
print 'end'
while True:
    line = p.stdout.readline().strip('\n\r')
    if line.find('AutoSandBox')>0 and line[-1]=='}':
        showline(line[line.find('{'):])



#
#a = 'SFRUUC8xLjEgMjAwIE9LDQpDb250ZW50LVR5cGU6IHRleHQvcGxhaW4NCkV4cGlyZXM6IFdlZCwg%0AMTIgTWFyIDIwMTQgMTE6MTU6NDIgR01UDQpDYWNoZS1Db250cm9sOiBtYXgtYWdlPTg2NDAwDQpD%0Ab250ZW50LUxlbmd0aDogMjYNCkNvbm5lY3Rpb246IGNsb3NlDQpEYXRlOiBUdWUsIDExIE1hciAy%0AMDE0IDExOjE1OjQyIEdNVA0KU2VydmVyOiBhcGFjaGUNCg0KeyJjdHIiOiIxOTY2MTkiLCJ2ZXIi%0AOiIwIn0%3D';
#b = urllib.unquote(a) 
#print b
#print base64.b64decode(b);
#print urllib.quote('a\na')
#print urllib.unquote('XBl%0AOiBhcHB') 

